/**
 * @description 匹配url的参数
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} name 
 * @returns  
 */
function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}

/**
 * @description 获取参数
 * @author xiezuobing[948466]<435321508@qq.com>
 */
function getQueryObject() {
  var search = window.location.search.substr(1).split('&');

  var query = {};
  $(search).each(function() {
    var qStr = this.split("=");
    if (qStr[0])
      query[qStr[0]] = qStr[1];
  });

  return query;
}

/**
 * @description 通过参数获取路径
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} object 
 * @returns  
 */
function getUrlByQuery(object) {
  object = object || {};
  var pathname = window.location.pathname;
  var prefix = '?';
  for (var key in object) {
    if (key && object[key]) {
      pathname += prefix + key + '=' + object[key];
      if (prefix == '?')
        prefix = '&';
    }
  }
  return pathname;
}

/**
 * @description 获取input的延迟触发
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} ele 
 * @param {function} callback 
 * @param {any} delay 
 */
function getInputDelayTrigger(ele, callback, delay) {
  delay = delay || 500;
  var timer;
  $(ele).on('input', function(e) {
    var that = $(this);
    if (timer) clearTimeout(timer);
    timer = setTimeout(function() {
      callback && callback(that.val());
    }, delay);
  })
}

/**
 * @description 检查是否为url
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} urlString 
 * @returns  
 */
function checkUrl(urlString) {
  if (urlString != "") {
    var reg = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
    if (reg.test(urlString)) {
      return true;
    }
  }
  return false;
}

//弹出窗口
function toastProp(data) {
  if (data.errCode == 0) {
    location.reload();
  } else {
    layer.msg(data.errMsg);
  }
}

/**
 * @description 校验特殊字符
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} str 
 * @returns {boolean} 
 */
function isSpecialStr(str) {
  var regEn = /[`~!@#$%^&*()+<>?:"{},\/;'[\]]/im,
    regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
  if (regEn.test(str) || regCn.test(str)) {
    return true;
  }
  return false;
}

/**
 * @description 计算字符长度
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} str 
 * @returns  
 */
function chkstrlen(str) {
  var strlen = 0;
  for (var i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) > 255) //如果是汉字，则字符串长度加2
      strlen += 2;
    else
      strlen++;
  }
  return strlen;
}

/**
 * @description 判断是否为汉字
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} val 
 * @returns  
 */
function CheckChinese(val) {
  var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
  if (reg.test(val)) {
    return true
  }
  return false;
}

/**
 * @description 是否中及下滑线含有中线
 * @author xiezuobing[948466]<435321508@qq.com>
 * @param {any} nickname 
 * @returns  
 */
function reg_check_val(nickname) {
  var regex = new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[^a-z|A-Z|0-9|\-|_|\.]){1,10}$");
  var res = regex.test(nickname);
  if (res == true) {
    return true;
  } else {
    return false;
  }
}